package br.com.massai.model.entity;

import java.math.BigDecimal;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.envers.Audited;

import br.com.massai.view.enums.RegimeEnum;

@Entity
@Audited
@Table(name = "ENTRY")
@NamedQueries({
	@NamedQuery(name = "Entry.find", query = "SELECT e FROM Entry e"),
	@NamedQuery(name = "Entry.duplicate", query = "SELECT e FROM Entry e WHERE e.spreadsheet =:spreadsheet")
})
public class Entry extends GenericEntity {

	private static final long serialVersionUID = 6851623934095869094L;

	@Id
	@SequenceGenerator(name = "seqEntry", sequenceName = "seq_entry", allocationSize = 1)
	@GeneratedValue(generator = "seqEntry", strategy = GenerationType.SEQUENCE)
	private Long id;

	@Enumerated(EnumType.STRING)
	@Column(name = "REGIME", columnDefinition = "CHAR(1)")
	private RegimeEnum regime;

	@Column(name = "TOTAL_AMOUNT", precision = 10, scale = 2, columnDefinition = "NUMERIC(10,2)")
	private BigDecimal totalAmount;

	@Column(name = "TOTAL_PERCENTAGE", precision = 7, scale = 4, columnDefinition = "NUMERIC(7,4)")
	private BigDecimal totalPercentage;

	@Column(name = "VALUE_GRATIFICATION", precision = 10, scale = 2, columnDefinition = "NUMERIC(10,2)")
	private BigDecimal valueGratification;

	@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "SPREADSHEET_ID", referencedColumnName = "ID")
	private Spreadsheet spreadsheet;
	
	//TODO add relationship with EMPLOYEE

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public RegimeEnum getRegime() {
		return regime;
	}

	public void setRegime(RegimeEnum regime) {
		this.regime = regime;
	}

	public BigDecimal getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(BigDecimal totalAmount) {
		this.totalAmount = totalAmount;
	}

	public BigDecimal getTotalPercentage() {
		return totalPercentage;
	}

	public void setTotalPercentage(BigDecimal totalPercentage) {
		this.totalPercentage = totalPercentage;
	}

	public BigDecimal getValueGratification() {
		return valueGratification;
	}

	public void setValueGratification(BigDecimal valueGratification) {
		this.valueGratification = valueGratification;
	}

	public Spreadsheet getSpreadsheet() {
		return spreadsheet;
	}

	public void setSpreadsheet(Spreadsheet spreadsheet) {
		this.spreadsheet = spreadsheet;
	}
}